home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLOBSH.PAK / PRIORTYQ.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  122 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  PRIORTYQ.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __PRIORTYQ_H )
  11. #define __PRIORTYQ_H
  12.  
  13. #define BI_OLDNAMES
  14.  
  15. #if !defined( __BTREE_H )
  16. #include "classlib\obsolete\Btree.h"
  17. #endif
  18.  
  19. #if !defined( __SHDDEL_H )
  20. #include "classlib\ShdDel.h"
  21. #endif  // __SHDDEL_H
  22.  
  23. #pragma option -Vo-
  24. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  25. #pragma option -po-
  26. #endif
  27.  
  28. _CLASSDEF(PriorityQueue)
  29.  
  30. class _CLASSTYPE PriorityQueue :
  31.     public Container,
  32.     public virtual Object::TShouldDelete
  33. {
  34.  
  35. public:
  36.  
  37.     int isEmpty() const
  38.         {
  39.         return tree.isEmpty();
  40.         }
  41.  
  42.     countType getItemsInContainer() const
  43.         {
  44.         return tree.getItemsInContainer();
  45.         }
  46.  
  47.     void put(Object& o)
  48.         {
  49.         tree.add(o);
  50.         }
  51.  
  52.     Object& get()
  53.         {
  54.         if( isEmpty() )
  55.             return NOOBJECT;
  56.         else
  57.             {
  58.             Object& obj = tree[0];
  59.             tree.detach( obj ); // does not delete
  60.             return obj;
  61.             }
  62.         }
  63.  
  64.     Object& peekLeft()
  65.         {
  66.         return (isEmpty()?NOOBJECT:tree[0]);
  67.         }
  68.  
  69.     void detachLeft( DeleteType dt = NoDelete )
  70.         {
  71.         if( !isEmpty() )
  72.             tree.detach( tree[0], dt );
  73.         }
  74.  
  75.     void flush( DeleteType dt = DefDelete )
  76.         {
  77.         tree.flush( dt );
  78.         }
  79.  
  80.     int hasMember( Object& obj ) const
  81.         {
  82.         return tree.hasMember( obj );
  83.         }
  84.  
  85.     int ownsElements()
  86.         {
  87.         return tree.ownsElements();
  88.         }
  89.  
  90.     void ownsElements( int del )
  91.         {
  92.         tree.ownsElements( del );
  93.         }
  94.  
  95.     virtual classType isA() const
  96.         {
  97.         return priorityQueueClass;
  98.         }
  99.  
  100.     virtual _TCHAR _FAR *nameOf() const
  101.         {
  102.         return "PriorityQueue";
  103.         }
  104.  
  105.     virtual ContainerIterator _FAR & initIterator() const
  106.         {
  107.         return tree.initIterator();
  108.         }
  109.  
  110. private:
  111.  
  112.     Btree tree;
  113.  
  114. };
  115.  
  116. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  117. #pragma option -po.
  118. #endif
  119. #pragma option -Vo.
  120.  
  121. #endif
  122.